package cn.buk.flight.entity;

import cn.buk.common.util.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

@Entity
@Table(name="fd_result")
public class FdResult {
	
	@Id
	@GeneratedValue(strategy= GenerationType.IDENTITY)
	private int id;

	@Column(name = "enterprise_id")
	private int enterpriseId;
	
	@Column(length=2)
	private String carrier;
	
	@Column(length=3)
	private String dport;

	@Column(length=3)
	private String aport;

	@JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
	@Temporal(TemporalType.DATE)
	private Date ddate;
	
	@Column(length=2)
	private String subclass;
	
	@Column(length=5)
	private String fareclass;

	@Column(length=1)
	private String cabinclass;
	
	@Column(name="price_ow", precision=6)
	private int owPrice;
	
	@Column(name="price_rt", precision=6)
	private int rtPrice;

	@JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
	@Temporal(TemporalType.DATE)
	@Column(name="date_effect")
	private Date effectDate;

	@JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
	@Temporal(TemporalType.DATE)
	@Column(name="date_expire")
	private Date expireDate;
	
	@Column(name="routetype_ow", length=2)
	private String owRouteType;

	@Column(name="routetype_rt", length=2)
	private String rtRouteType;

	@Column(length=4)
	private String ruleno;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
	@Column(name="lastupdate")
	private Date lastupdate;

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the carrier
	 */
	public String getCarrier() {
		return carrier;
	}

	/**
	 * @param carrier the carrier to set
	 */
	public void setCarrier(String carrier) {
		this.carrier = carrier;
	}

	/**
	 * @return the subclass
	 */
	public String getSubclass() {
		return subclass;
	}

	/**
	 * @param subclass the subclass to set
	 */
	public void setSubclass(String subclass) {
		this.subclass = subclass;
	}

	/**
	 * @return the fareclass
	 */
	public String getFareclass() {
		return fareclass;
	}

	/**
	 * @param fareclass the fareclass to set
	 */
	public void setFareclass(String fareclass) {
		this.fareclass = fareclass;
	}

	/**
	 * @return the cabinclass
	 */
	public String getCabinclass() {
		return cabinclass;
	}

	/**
	 * @param cabinclass the cabinclass to set
	 */
	public void setCabinclass(String cabinclass) {
		this.cabinclass = cabinclass;
	}

	/**
	 * @return the owPrice
	 */
	public int getOwPrice() {
		return owPrice;
	}

	/**
	 * @param owPrice the owPrice to set
	 */
	public void setOwPrice(int owPrice) {
		this.owPrice = owPrice;
	}

	/**
	 * @return the effectDate
	 */
	public Date getEffectDate() {
		return effectDate;
	}

	/**
	 * @param effectDate the effectDate to set
	 */
	public void setEffectDate(Date effectDate) {
		this.effectDate = effectDate;
	}

	/**
	 * @return the expireDate
	 */
	public Date getExpireDate() {
		return expireDate;
	}

	/**
	 * @param expireDate the expireDate to set
	 */
	public void setExpireDate(Date expireDate) {
		this.expireDate = expireDate;
	}

	/**
	 * @return the owRouteType
	 */
	public String getOwRouteType() {
		return owRouteType;
	}

	/**
	 * @param owRouteType the owRouteType to set
	 */
	public void setOwRouteType(String owRouteType) {
		this.owRouteType = owRouteType;
	}

	/**
	 * @return the ruleno
	 */
	public String getRuleno() {
		return ruleno;
	}

	/**
	 * @param ruleno the ruleno to set
	 */
	public void setRuleno(String ruleno) {
		this.ruleno = ruleno;
	}

	/**
	 * @return the rtRouteType
	 */
	public String getRtRouteType() {
		return rtRouteType;
	}

	/**
	 * @param rtRouteType the rtRouteType to set
	 */
	public void setRtRouteType(String rtRouteType) {
		this.rtRouteType = rtRouteType;
	}

	/**
	 * @return the lastupdate
	 */
	public Date getLastupdate() {
		return lastupdate;
	}

	/**
	 * @param lastupdate the lastupdate to set
	 */
	public void setLastupdate(Date lastupdate) {
		this.lastupdate = lastupdate;
	}

	/**
	 * @return the rtPrice
	 */
	public int getRtPrice() {
		return rtPrice;
	}

	/**
	 * @param rtPrice the rtPrice to set
	 */
	public void setRtPrice(int rtPrice) {
		this.rtPrice = rtPrice;
	}

	public int getEnterpriseId() {
		return enterpriseId;
	}

	public void setEnterpriseId(int enterpriseId) {
		this.enterpriseId = enterpriseId;
	}

	public String getDport() {
		return dport;
	}

	public void setDport(String dport) {
		this.dport = dport;
	}

	public String getAport() {
		return aport;
	}

	public void setAport(String aport) {
		this.aport = aport;
	}

	public static StringBuilder exportHeaderToStringBuffer() {
		StringBuilder sb = new StringBuilder();

		sb.append("航空公司,");
		sb.append("出发机场,");
		sb.append("到达机场,");
		sb.append("FD日期,");

		sb.append("销售舱位,");
		sb.append("运价基础,");
		sb.append("物理舱位,");

		sb.append("单程价格,");
		sb.append("往返价格,");

		sb.append("生效日期,");
		sb.append("失效日期");
		sb.append("ruleno,");

		sb.append("\r");

		return sb;
	}

	public StringBuilder exportContentToStringBuffer() {
		StringBuilder sb = new StringBuilder();

		sb.append(this.carrier).append(",");
		sb.append(this.dport).append(",");
		sb.append(this.aport).append(",");
		if (this.ddate != null) {
      sb.append(DateUtil.formatDate(this.ddate, "yyyy-MM-dd"));
    }
		sb.append(",");

		sb.append(this.subclass).append(",");
		sb.append(this.fareclass).append(",");
		sb.append(this.cabinclass).append(",");

		if (this.owPrice > 0) {
      sb.append(this.owPrice);
    }
		sb.append(",");
		if (this.rtPrice > 0) {
      sb.append(this.rtPrice);
    }
		sb.append(",");

		sb.append(this.effectDate).append(",");

		if (this.expireDate != null) {
      sb.append(this.expireDate);
    }
		sb.append(",");

		sb.append(this.ruleno).append(",");

		sb.append("\r");

		return sb;
	}

	public Date getDdate() {
		return ddate;
	}

	public void setDdate(Date ddate) {
		this.ddate = ddate;
	}
}